package com.xyh.flowershop.config;


import ch.qos.logback.core.testUtil.RandomUtil;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.customizers.GlobalOpenApiCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


/**
 * @author 小约翰可汗
 * @className Swagger2Config
 * @createTime 2024/4/120:31
 */
@Configuration
@EnableKnife4j
public class Swagger2Config {

   @Bean
   public GlobalOpenApiCustomizer orderGlobalOpenApiCustomizer() {
       return openApi -> {
           if (openApi.getTags()!=null){
               openApi.getTags().forEach(tag -> {
                   Map<String,Object> map=new HashMap<>();
                   map.put("x-order", RandomUtil.getPositiveInt());
                   tag.setExtensions(map);
               });
           }
           if(openApi.getPaths()!=null){
               openApi.addExtension("x-test123","333");
               openApi.getPaths().addExtension("x-abb",RandomUtil.getPositiveInt());
           }

       };
   }
   @Bean
   public OpenAPI customOpenAPI() {
       return new OpenAPI()
               .info(new Info()
                       .title("小约翰花店文档")
                       .version("1.0")
                       .description( "小约翰的花店接口文档")
                       .termsOfService("暂无")
                       .contact(new Contact().name("小约翰"))
                       .license(new License().name("Apache 2.0")
                               .url("127.0.0.1:8080")));
   }

}
